
import 'package:cunyutech_flutter_ui/src/theme/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

class CYLinkButton extends StatelessWidget {
  final String title;
  final VoidCallback onTap;
  final Color color;
  final double height;
  final double width;
  final EdgeInsetsGeometry margin;
  final EdgeInsetsGeometry padding;
  final double fontSize;
  final bool loading;

  const CYLinkButton(
    this.title, {
    Key key, 
    this.onTap, 
    this.color,
    this.height,
    this.width,
    this.margin,
    this.padding,
    this.fontSize,
    this.loading
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var cs = CYThemeData.of(context);
    final Widget content = Text(
      title,
      style: TextStyle(
        color: color ?? cs.linkColor,
        fontSize: fontSize,
      ),
    );
    final Widget loadingWidget = SpinKitFadingCircle(color: Colors.white, size: 22);
    return Container(
      margin: margin,
      child: GestureDetector(
        onTap: onTap,
        child: Container(
          height: height,
          width: width,
          padding: padding,
          alignment: Alignment.center,
          color: Colors.transparent,
          child: loading == true ? loadingWidget : content
        )
      )
    );
  }
}